#include <bits/stdc++.h>
#include <string>
#include <map> // 映射
using namespace std;

#define N 100
#define inf 99999

/** 图 */
struct Graph
{
    int markNumber;       // 点的个数
    bool direction;       // 有向图：true  无向图：false
    int m[N][N];          // 路径
    map<string, int> add; // 映射关系   [["guiyang",0],["anshun",1],["zhunyi",2]]
};

/** 初始化 */
struct Graph initGraph(struct Graph p, bool dir = false)
{
    p.markNumber = 0;
    p.direction = dir;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            p.m[i][j] = inf;
        }
    }
    return p;
}

/** 添加点 */
struct Graph addMark(struct Graph p, string name)
{
    if (p.add.find(name) != p.add.end())
        return p;
    p.add[name] = p.markNumber;
    p.m[p.markNumber][p.markNumber] = 0;
    p.markNumber++;
    return p;
}

/** 添加一条边 */
struct Graph addLine(struct Graph p, string b, string e, int len)
{
    if (b == e)
        return p;
    p = addMark(p, b);
    p = addMark(p, e);
    // 获取开始,结束位置的映射整数索引
    int b_n = p.add.find(b)->second, e_n = p.add.find(e)->second;
    p.m[b_n][e_n] = len;
    // 无向图，需要反向设置长度
    if (!p.direction)
        p.m[e_n][b_n] = len;
    return p;
}

int getLen(struct Graph p, string b, string e)
{
    // 获取开始,结束位置的映射整数索引
    int b_n = p.add.find(b)->second, e_n = p.add.find(e)->second;
    return p.m[b_n][e_n];
}

/** 求图p中由b->e的最短距离 */
int getMinLen(struct Graph p, string b, string e)
{
    int n = p.markNumber;
    int x[n][n];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            x[i][j] = p.m[i][j];
        }
    }
    for (int k = 0; k < n; k++)
    {
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (x[i][j] > x[i][k] + x[k][j])
                {
                    x[i][j] = x[i][k] + x[k][j];
                }
            }
        }
    }
    // 获取开始,结束位置的映射整数索引
    int b_n = p.add.find(b)->second, e_n = p.add.find(e)->second;
    return x[b_n][e_n];
}

int main()
{

    struct Graph g;
    g = initGraph(g);
    g = addLine(g, "guiyang", "anshun", 10);
    g = addLine(g, "guiyang", "zhunyi", 20);
    g = addLine(g, "anshun", "zhunyi", 5);
    cout << getLen(g, "guiyang", "zhunyi") << endl;
    cout << getMinLen(g, "guiyang", "zhunyi") << endl;
    return 0;
}